package Greedy;

public class _714_BestTimetoBuyandSellStockwithTransactionFee {
    public int maxProfit(int[] prices, int fee) {
        int cash = 0, store = -prices[0];
        for (int i = 0; i < prices.length; i++) {
            cash = Math.max(cash, store + prices[i] - fee);//every loop,sell the bigger differences store（股价高的时候卖出）
            store = Math.max(store, cash - prices[i]);//every loop,buy the cheaper store（手上均为净现值+相同的股票（不考虑价格），不断选择净现值大的购入）
        }
        return cash;
    }
}
